/*
 * @Author: szx
 * @Date: 2022-03-01 14:10:16
 * @LastEditTime: 2022-03-01 14:20:22
 * @Description:
 * @FilePath: \leetcode\1600-1699\1685\1685.js
 */
/**
 * @param {number[]} nums
 * @return {number[]}
 */
var getSumAbsoluteDifferences = function (nums) {
    const n = nums.length;
    let right = nums.reduce((a, b) => a + b, 0);
    const res = new Array(n).fill(0);
    let left = 0;
    for (let i = 0; i < n; i++) {
        right -= nums[i];
        res[i] += right - (n - i - 1) * nums[i];
        res[i] += i * nums[i] - left;
        left += nums[i];
    }
    return res;
};
console.log(getSumAbsoluteDifferences([1,4,6,8,10]));
